package com.wtp.wallpaper.controller.admin;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wtp.wallpaper.pojo.dto.TabDTO;
import com.wtp.wallpaper.pojo.entity.Tabs;
import com.wtp.wallpaper.pojo.query.PageQuery;
import com.wtp.wallpaper.pojo.vo.TabVO;
import com.wtp.wallpaper.pojo.result.Result;
import com.wtp.wallpaper.service.TabsService;
import com.wtp.wallpaper.utils.PojoConvertUtil;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@RestController("adminTabsController")
@Slf4j
@RequestMapping("/admin")
public class TabsController {

    @Resource
    private TabsService tabsService;

    @GetMapping("/tabList")
    public Result tabList(){
        return Result.success(PojoConvertUtil.convert(tabsService.list(),TabVO.class));
    }

    @GetMapping("/tabPage")
    public Result queryTabPage(@RequestParam(defaultValue = "1") int pageNum,
                               @RequestParam(defaultValue = "5") int pageSize){
        Page<Tabs> page = tabsService.page(new PageQuery(pageNum, pageSize).toMpPageDefaultSortByCreateTime());
        return Result.success(PojoConvertUtil.convert(page, TabVO.class));
    }

    @PostMapping("/tab/removeByIds")
    public Result removeByIds(TabDTO tabDTO){
        log.info("传来ids:{}",tabDTO);
        tabsService.removeTabsByIds(tabDTO);
        //pictureService.removeByIds();
        return Result.success();
    }

    @PostMapping("/tab/addOne")
    public Result addOneTab(TabDTO tabDTO){
        log.info("传来数据:{}",tabDTO);
        tabsService.addOne(tabDTO);
        return Result.success();
    }

    @PostMapping("/tab/modifyOne")
    public Result modifyOnePicture(TabDTO tabDTO){
        log.info("传来数据:{}",tabDTO);
        tabsService.update(tabDTO);
        return Result.success();
    }

}
